package cn.labbook.bluetooth.mapper;

import cn.labbook.bluetooth.common.MyPage;
import cn.labbook.bluetooth.entity.ApplyRecord;
import cn.labbook.bluetooth.pojo.dto.ApplyRecordDTO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: zhangyang
 * @Date: 2023/4/13 14:33
 * @Desc: 申请记录 mapper
 */
public interface ApplyRecordMapper extends BaseMapper<ApplyRecord> {

    @Select("SELECT apply.id as id,amm.location,apply.status,apply.amount,apply.zkis_platform_amount as zkisPlatformAmount," +
            "apply.create_time as createTime,apply.ammeter_id as ammeterId,apply.is_skimp as isSkimp " +
            "from apply_record apply LEFT JOIN ammeter amm on apply.ammeter_id = amm.ammeter_id ${ew.customSqlSegment} ")
    List<ApplyRecordDTO> listWithLandlord(@Param("ew") Wrapper<ApplyRecord> wrapper, MyPage<ApplyRecord> page);

    @Select("SELECT apply.id as id,amm.location,apply.status,apply.amount,apply.zkis_platform_amount as zkisPlatformAmount," +
            "apply.create_time as createTime,apply.ammeter_id as ammeterId,apply.is_skimp as isSkimp " +
            "from apply_record apply LEFT JOIN ammeter amm on apply.ammeter_id = amm.ammeter_id ${ew.customSqlSegment} ")
    List<ApplyRecordDTO> listWithTenant(@Param("ew") Wrapper<ApplyRecord> wrapper, MyPage<ApplyRecord> page);

    @Select("SELECT apply.pay_true_amount,apply.amount,apply.status from apply_record apply LEFT JOIN ammeter amm on apply.ammeter_id = amm.ammeter_id ${ew.customSqlSegment}")
    List<ApplyRecord> getSumPay(@Param("ew") Wrapper<ApplyRecord> wrapper);

    @Select("SELECT count(apply.id) " +
            "from apply_record apply LEFT JOIN ammeter amm on apply.ammeter_id = amm.ammeter_id ${ew.customSqlSegment} ")
    Integer countWithLandlord(@Param("ew") Wrapper<ApplyRecord> wrapper);

}
